<template>
  <div class="charts" ref="progress"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "",
  //初始化echarts实例
  mounted() {
    let mycharts = echarts.init(this.$refs.progress);
    //配置项
    let option = {
      xAxis: {
        show: false,
        //设置最小数值
        min: 0,
        max: 100,
      },
      yAxis: {
        type: "category",
        show: false,
      },
      //布局
      grid: {
        left: 0,
        right: 0,
        top: 0,
        bottom: 0,
      },
      series: {
        type: "bar",
        color: {
          type: "linear",
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: "black", // 0% 处的颜色
            },
            {
              offset: 1,
              color: "#eee", // 100% 处的颜色
            },
          ],
          global: false, // 缺省为 false
        },
        data: [70],
        //柱状图宽度
        barWidth: 10,
        label: {
          show: true,
          position: "right",
          //图文标签内容
          formatter: "|",
        },
        //展示背景颜色
        showBackground: true,
        //调试背景颜色
        backgroundStyle: {
          color: "#eee",
        },
      },
    };
    //设置配置项
    mycharts.setOption(option);

     window.addEventListener("resize", () => {
      //图标自适应
      mycharts.resize();
    });
  },
};
</script>

<style scoped>
.charts {
  width: 100%;
  height: 100%;
}
</style>
